#pragma once

#include <QtGui/QWidget>
#include <QtUi/ModelTest.hpp>

#include "GeneratedFiles/ui/ui_ErrorWidget.h"
#include "State.hpp"
#include "ErrorModel.hpp"
#include "MergedErrorModel.hpp"




namespace Engine
{
	namespace Edit
	{
		/**
		 * This widget's purpose is to display one or more ErrorModels.
		 *
		 * It also emits signals when the user clicked/double clicked a specific entry.
		 * This can be used to show the user where the error originated from (for example
		 * by bringing the appropriate view to the front and showing the line / whatever
		 * that is responsible for the error).
		 */
		class ErrorWidget
			: public QWidget
		{
			Q_OBJECT

		public:

			ErrorWidget(QWidget* parent);
			virtual ~ErrorWidget();



			void changeState(State::Type state);



			/**
			 * Adds the given model to this widget.
			 */
			void add(ErrorModel::const_ptr model);

			/**
			 * Removes the given model from this widget.
			 */
			void remove(ErrorModel::const_ptr model);

		public slots:

			void modelChanged();
			void restoreSettings(QSettings& settings);
			void saveSettings(QSettings& settings) const;
			void updateLevels();

		signals:

			/**
			 * This signal is emitted whenever a user requested to see what causes
			 * an error of a specific model.
			 * An appropriate action would be to highlight (and set the focus to)
			 * the view, the error originated in, as well as the exact location.
			 */
			void showMessage(logger::entry message, ErrorModel::const_ptr model);

		private:

			::Ui::ErrorWidget       ui;

			State::Type             m_state;
			MergedErrorModel        m_model;
			QSortFilterProxyModel   m_proxyModel;
			ModelTest               m_modelTest;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
